package cn.coufran.springboot.starter.http.content;

import cn.coufran.springboot.starter.http.MultipartBody;

import java.io.InputStream;

/**
 * @author Coufran
 * @version 2.0.0
 * @since 2.0.0
 */
public class StreamContent extends HttpBodyContent<InputStream> implements HttpRequestBodyContent {
    private InputStream content;

    public StreamContent(String name, InputStream content) {
        super(name);
        this.content = content;
    }

    public StreamContent(InputStream content) {
        this.content = content;
    }

    @Override
    public void accept(MultipartBody.Builder multipartBodyBuilder) {
        multipartBodyBuilder.addPart(name(), content());
    }

    @Override
    public InputStream getInputStream() {
        return content;
    }

    @Override
    public InputStream content() {
        return this.content;
    }


    @Override
    public String toString() {
        return "StreamContent{" +
                "content=" + content +
                "} " + super.toString();
    }
}
